package com.test;

public class Tx {

    public static  class Node{
        Node left;
        Node right;
        int d;
        public Node(int d){
            this.d=d;
        }
    }
    public static void main(String[] args) {

        Node n1 = new Node(1);
        Node n2 = new Node(2);
        Node n3 = new Node(3);n1.left=n2;n1.right=n3;
        Node n4 = new Node(4);
        Node n5 = new Node(5);n2.left=n4;n2.right=n5;


        Node ret = lcf(n1,3,5);
        System.out.println(ret.d);
    }

    public static Node lcf(Node root,int a,int b){
        if(root==null || root.d==a || root.d==b){
            return root;
        }
        Node leftRet = lcf(root.left,a,b);
        Node rightRet = lcf(root.right,a,b);
        if(leftRet==null){
            return rightRet;
        }
        if(rightRet==null){
            return leftRet;
        }
        return root;
    }

}
